var date = new Date();
var currentYear = date.getFullYear();       // 当前年份
var currentMonth = date.getMonth() + 1;    // 当前月份
var currentDay = date.getDate();         // 今日日期 几号
if (currentMonth < 10) currentMonth = "0" + currentMonth;
if (currentDay < 10) currentDay = "0" + currentDay;
var nowTime = currentYear + "-" + currentMonth + "-" + currentDay;
//回访完成
var count2 = 0;
$("#submit2").click(function () {
    var followStatus = $("#followStatus").val();
    var consumptionStatus = $("#consumptionStatus").val();
    var tcName = document.getElementById("tcName").value;   //tc
    var createName = document.getElementById("createName").value;  //创建人
    var remarks = document.getElementById("remarks").value;   //回访内容
    var revisit = document.getElementById("revisit").value;   //回访人员
    var revisitContent = document.getElementById("revisitContent").value;   //回访结果
    var reservationsId = document.getElementById("reservationsId").value;   //预约id
    var revisitTime = document.getElementById("revisitTime").value;   //回访时间
    var tcVisitId = document.getElementById("tcVisitId").value;   //ID
    if (revisit == null || revisit == "") {
        alert("请选择回访人员!");
        count2 = 0;
        return;
    }
    if (revisitTime.substring(0, 10) < nowTime && (followStatus == "" || followStatus == null || followStatus == "跟踪中")) {
        alert("下次跟进时间要不小于今天！");
        count2 = 0;
        return
    }
    if (followStatus == null || followStatus == "" || followStatus == "请选择") {
        alert("请选择跟踪状态!");
        count2 = 0;
        return;
    }
    if (consumptionStatus == null || consumptionStatus == "" || consumptionStatus == "请选择") {
        alert("请选择消费状态!");
        count2 = 0;
        return;
    }
    if ((revisitContent == null || revisitContent == "")) {
        alert("请填写回访结果!");
        count2 = 0;
        return;
    }
    count2++;
    if (count2 == 1) {
        $.ajax({
            url: Feng.ctxPath + "/tcRevisit/updateTcContentOver1",
            type: "post",
            data: {
                tcName: tcName,
                followStatus: followStatus,
                consumptionStatus: consumptionStatus,
                revisitTime: revisitTime,
                createName: createName,
                remarks: remarks,
                revisit: revisit,
                revisitContent: revisitContent,
                reservationsId: reservationsId,
                tcVisitId: tcVisitId
            },
            success: function (data) {
                Feng.success('操作成功!');
                window.parent.TcRevisit.inquire();
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
});
//再回访
var countz = 0;
$("#submitZ").click(function () {
    var revisit = document.getElementById("revisit").value;//回访人员
    var followStatus = $("#followStatus").val();
    var consumptionStatus = $("#consumptionStatus").val();
    var remarks = $("#remarks").val();
    if (revisit == null || revisit == "") {
        alert("请选择回访人员!");
        countz = 0;
        return;
    }
    if (followStatus == null || followStatus == "") {
        alert("请选择跟踪状态!");
        countz = 0;
        return;
    }
    if (consumptionStatus == null || consumptionStatus == "") {
        alert("请选择消费状态!");
        countz = 0;
        return;
    }
    if (remarks == null || remarks == "") {
        alert("请填写回访计划!");
        countz = 0;
        return;
    }
    var index = layer.open({
        type: 2,
        title: '再回访',
        area: ['60%', '50%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tcRevisit/tc_followUp'
    });
    this.layerIndex = index;
});
//添加随访模板
function addsf() {
    var index = layer.open({
        type: 2,
        title: '&nbsp',
        area: ['60%', '40%'],
        fix: true,
        maxmin: true,
        content: Feng.ctxPath + '/tcRevisit/to_addsf/'
    });
    this.layerIndex = index;
};
//添加随访结果模板
function addjg() {
    var index = layer.open({
        type: 2,
        title: '&nbsp',
        area: ['60%', '40%'],
        fix: true,
        maxmin: true,
        content: Feng.ctxPath + '/tcRevisit/to_addjg/'
    });
    this.layerIndex = index;
};